package com.ruoyi.app;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.ruoyi.common.core.domain.AddressObject;
import com.ruoyi.common.core.domain.FileObject;

import java.io.IOException;
import java.util.List;

/**
 * 描述 图片JSON字符串转实体类
 * 作者 ZhangPing
 * 创建时间 2023/9/21 11:25
 */
public class AddressObjectDeserializer extends JsonDeserializer<List<AddressObject>> {

    @Override
    public List<AddressObject> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        if (jsonParser.getCurrentToken().equals(JsonToken.VALUE_STRING)) {
            return JSON.parseArray(jsonParser.getText(), AddressObject.class);
        }
        return jsonParser.readValueAs(new TypeReference<List<AddressObject>>(){});
    }
}